package cave.ui;

import android.graphics.Color;
import android.util.FloatMath;
import cave.renderer.RenderList;
import cave.renderer.Texture;

public class Image implements StaticUiItem {
	
	private float x, y;
	private float width, height;
	private float red, green, blue, alpha;
	private float[] orientation;
	private Texture texture;
	
	public Image(float x, float y, float width, float height, Texture texture) {
		this(x, y, width, height, texture, 1.0f, 1.0f, 1.0f, 1.0f);
	}
	
	public Image(float x, float y, float width, float height, Texture texture, int color) {
		this(x, y, width, height, texture, Color.red(color) / 255.0f, Color.green(color) / 255.0f,
				Color.blue(color) / 255.0f, Color.alpha(color) / 255.0f);
	}
	
	public Image(float x, float y, float width, float height, Texture texture,
			float red, float green, float blue, float alpha) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.texture = texture;
		this.red = red;
		this.green = green;
		this.blue = blue;
		this.alpha = alpha;
		orientation = new float[2];
		orientation[0] = 0.0f;
		orientation[1] = 1.0f;
		texture.incUsers();
	}

	@Override
	public void draw(RenderList renderList) {
		renderList.addScreenData(x, y, width, height, orientation[0], orientation[1],
				texture, red, green, blue, alpha);
	}

	@Override
	public void destroy() {
		texture.decUsers();
	}
	
	public void setOrientation(float x, float y) {
		orientation[0] = x; orientation[1] = y;
	}
	
	public void setOrientation(float radians) {
		orientation[0] = FloatMath.cos(radians + (float)Math.PI/2);
		orientation[1] = FloatMath.sin(radians + (float)Math.PI/2);
	}
	
	public float[] getOrientation() {
		return orientation;
	}
	
	public void setPosition(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public float getX() {
		return x;
	}
	
	public float getY() {
		return y;
	}
	
	public void setX(float x) {
		this.x = x;
	}
	
	public void setY(float y) {
		this.y = y;
	}
	
	public float getWidth() {
		return width;
	}
	
	public float getHeight() {
		return height;
	}
	
	public void setWidth(float width) {
		this.width = width;
	}
	
	public void setHeight(float height) {
		this.height = height;
	}

}
